<template>
	<!-- 企业添加 -->
	<div>
		<div class="edit-top">
			添加信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">企业信息</div>
			<div class="edit-item">
				<label>企业编号</label><input v-model="info.enterpriseCode" type="text" />
			</div>
			<div class="edit-item">
				<label>企业名称</label><input v-model="info.enterpriseName" type="text" />
			</div>
			<div class="edit-item" style="overflow: hidden;">
				<label style="float: left;">企业地址</label><textarea v-model="info.enterpriseAddress" rows="2"/>
			</div>
			
			<div class="edit-item">
				<label>企业类型</label>
				<el-radio v-for='item in dict.enterpriseType' :key='item.value' v-model="info.enterpriseType" :label="item.value">{{item.type}}</el-radio>
				<!-- <select v-model="info.enterpriseType">
					<option v-for='item in dict.enterpriseType' :value="item.value">{{item.type}}</option>
				</select> -->
			</div>
			<!-- <div class="edit-item">
				<label>企业状态</label><select v-model="info.enterpriseStatus">
					<option v-for='item in dict.enterpriseStatus' :value="item.value">{{item.type}}</option>
				</select>
			</div> -->
			<div class="edit-item">
				<label>联系人</label><input v-model="info.contactPersonName" type="text" />
			</div>
			<div class="edit-item">
				<label>联系电话</label><input v-model="info.contactPersonPhone" type="text" />
			</div>
			<!-- <div class="edit-title">开户信息</div> -->
			<div class="edit-item">
				<label>开户账号</label><input v-model="info.bankNum" type="text" />
			</div>
			<div class="edit-item">
				<label>开户姓名</label><input v-model="info.accountName" type="text" />
			</div>
			<div class="edit-item">
				<label>开户行</label><input v-model="info.openingBank" type="text" />
			</div>
		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	let _this;
	export default {
		data() {
			return {
				dict: '',
				info: {
					openingBank: '',
					accountName: '',
					bankNum: '',
					contactClientId: '0',
					contactPersonName: '',
					contactPersonPhone: '',
					enterpriseAddress: '',
					enterpriseCode: '',
					enterpriseName: '',
					// enterpriseStatus: 0,
					enterpriseType: "0",
				}
			}
		},
		created() {
			_this = this;
		},
		mounted() {
			this.get_dict();
		},
		methods: {
			get_dict() {
				this.$axios.get(this.$global.serverIp + 'admin/dict/findDict?keyword=sysEnterprise')
					.then(function(res) {
						if (res != '')
							_this.dict = res.data;
					})

			},
			save() {
				if (this.info.enterpriseCode == "") {
					this.$popup.open('企业编号不能为空');
					return;
				}
				if (this.info.enterpriseName == "") {
					this.$popup.open('企业名称不能为空');
					return;
				}
				if (this.info.enterpriseAddress == "") {
					this.$popup.open('企业地址不能为空');
					return;
				}
				if (this.info.contactPersonName == "") {
					this.$popup.open('联系人不能为空');
					return;
				}
				if (this.info.contactPersonPhone == "") {
					this.$popup.open('联系电话不能为空');
					return;
				}
				if (this.info.openingBank == "") {
					this.$popup.open('开户行不能为空');
					return;
				}
				if (this.info.accountName == "") {
					this.$popup.open('开户姓名不能为空');
					return;
				}
				if (this.info.bankNum == "") {
					this.$popup.open('开户账号不能为空');
					return;
				}
				this.$axios.post(this.$global.serverIp + 'admin/sysEnterprise/save', _this.info)
					.then(function(res) {
						if (res != '') {
							_this.success('添加成功');
						}
					})

			},
			success(content) {
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						_this.$emit("saveAdd", 2);
					}
				});
			},
			
			cancel() {
				this.$emit("saveAdd", 1);
			}
		}
	}
</script>
